package com.o2o.app.userCenter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import com.o2o.app.R;
import com.o2o.app.utils.MagusTools;

public class MineSettingActivity extends Activity {
	/**
	 * 点击通知设置
	 */
	private RelativeLayout rlt_01;

	/**
	 * 密码管理按钮
	 */
	private RelativeLayout rlt_02;

	/**
	 * 修改密码布局
	 */
	private PopupWindow foodPop = null;

	/**
	 * 返回
	 */
	private Button btn_back;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mine_setting);

		initViews();
	}

	private void initViews() {
		rlt_01 = (RelativeLayout) findViewById(R.id.rlt_01);
		rlt_01.setOnClickListener(new ClickEvent());

		rlt_02 = (RelativeLayout) findViewById(R.id.rlt_02);
		rlt_02.setOnClickListener(new ClickEvent());

		btn_back = (Button) findViewById(R.id.btn_back);
		btn_back.setOnClickListener(new ClickEvent());
	}

	/**
	 * 点击事件
	 * 
	 * @author Administrator
	 * 
	 */
	class ClickEvent implements View.OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.rlt_01: {

				Intent intent = new Intent(MineSettingActivity.this,
						MinePutInfoActivity.class);

				startActivity(intent);

			}
				break;

			case R.id.rlt_02: {
				foodPop = showPop(foodPop);
			}
				break;

			case R.id.btn_back: {
				finish();
			}
				break;
			default:
				break;
			}
		}

	}

	/**
	 * 修改密码
	 * 
	 * @param pop
	 * @return
	 */
	private PopupWindow showPop(PopupWindow pop) {
		if (pop == null) {
			pop = MagusTools.getPopupWindow(MineSettingActivity.this,
					R.layout.pop_change_code, R.style.wheel_animation,
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		}

		View view = pop.getContentView();

		RelativeLayout rlt_cancel = (RelativeLayout) view
				.findViewById(R.id.rlt_cancel);

		RelativeLayout rlt_confirm = (RelativeLayout) view
				.findViewById(R.id.rlt_confirm);

		rlt_cancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				foodPop.dismiss();
			}
		});

		rlt_confirm.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				foodPop.dismiss();
				Intent intent = new Intent(MineSettingActivity.this,
						MineRcodeActivity.class);

				startActivity(intent);

			}
		});

		View mainView = LayoutInflater.from(MineSettingActivity.this).inflate(
				R.layout.mine_user_edit, null);
		pop.showAtLocation(mainView, Gravity.CENTER, 0, 0);

		return pop;

	}

}
